<template>
  <h2>计算属性-computed</h2>
  <span>count: {{ count }}</span>
  <button @click="add">+</button>
  <p>doubleCount: {{ doubleCount }}</p>

  <hr />

  <ul>
    <li v-for="item in oddList" :key="item">{{ item }}</li>
  </ul>
</template>

<script>
import { ref, computed } from "vue";
export default {
  setup() {
    const count = ref(1);
    const add = () => {
      count.value++;
    };
    // computed它是函数调用，里面传入一个回调函数
    // 返回一个计算属性

    // computed是可以写多个的
    const doubleCount = computed(() => {
      return count.value * 2;
    });

    const list = ref([1, 2, 3, 4, 5, 6, 7]);
    const oddList = computed(() => list.value.filter((item) => item % 2));

    return { count, add, doubleCount, oddList };
  },
};
</script>
